package com.amiu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amiu.Bean;
import com.amiu.autoMybatis.test.mapper.DaoMapper;
import com.amiu.autoMybatis.test.mapper.DaoMapper2;
import com.amiu.service.Dao1Service;
import com.amiu.service.Dao2Service;

@RestController
public class SpringControllerTest {

//	@Autowired DaoMapper dao;
//	@Autowired DaoMapper2 dao2;
	@Autowired
	Dao1Service dao;
	@Autowired
	Dao2Service dao2;

	@RequestMapping("/testTransaction")
	@Transactional
	public String testTransaction() {
		try {
			
			System.out.println(dao.findById(7));
			Bean bean = new Bean("t", "t", "26628639639");
			dao.insert(bean);
			System.out.println("test insert return id:" + bean.getId());
			bean.setId(1);
			bean.setName("name");
			dao.updateById(bean);
			System.out.println("test1 update id:" + bean.getId() + "and value:"
					+ dao2.findById(bean.getId()));
			dao2.insert(bean);
			System.out.println("test1 insert return id:" + bean.getId());
		} catch (Exception ex) {
			throw ex;
		}
		
		return "true";
	}

	@RequestMapping("/testMybatisSpring")
	public Bean testMybatisSpring(@RequestBody Bean bean) {
		return dao.findById(bean.getId());
	}

	@RequestMapping("/testJson")
	public Bean testJson(@RequestBody Bean bean) {
		System.out.println("111111");

		return new Bean(bean.getId(), "json", "{jsonPwd}", "13930000");
	}

	@RequestMapping("/testParame")
	public Bean testParame(long id) {
		System.out.println("111111");

		return new Bean(id, "json", "{jsonPwd}", "13930000");
	}

	@RequestMapping("/toHello")
	public String toHello() {
		System.out.println("11");
		return "index";
	}
}
